package com.wcx.application.controller;

import com.wcx.application.domian.BossBean;
import com.wcx.application.domian.PositionBean;
import com.wcx.application.service.BossService;
import com.wcx.application.service.PositionService;
import com.wcx.application.utils.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

@RestController
@RequestMapping("/position")
@CrossOrigin
public class PositionController {

    @Autowired
    PositionService positionService;


    @GetMapping("/list")
    public Result getList() {
        System.out.println("---" + positionService.getList());
        return Result.ok().data("list", positionService.getList());
    }

    @PostMapping("/update")
    public Result update(@RequestBody PositionBean positionBean) {
        int i = positionService.update(positionBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }

    @PostMapping("/search")
    public Result search(@RequestBody PositionBean positionBean) {
        return Result.ok().data("list", positionService.searchList(positionBean));
    }

    @PostMapping("/create")
    public Result create(@RequestBody PositionBean positionBean) {

        int i = positionService.create(positionBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }

    }

    @DeleteMapping("/delete")
    public Result delete(int id) {
        int i = positionService.delete(id);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }
}